﻿using Compass.Wasm.Shared.Wms;
using Compass.Wasm.Shared;
using Compass.WmsService.Infrastructure;
using System.ComponentModel.DataAnnotations;
using Compass.Wasm.Server.Services.Wms;

namespace Compass.Wasm.Server.Controllers.Wms;

[Route("api/[controller]")]
[ApiController]
[UnitOfWork(typeof(WmsDbContext))]
public class CargoController : ControllerBase
{
    #region ctor
    private readonly ICargoService _service;
    public CargoController(ICargoService service)
    {
        _service = service;
    }
    #endregion

    #region 基本增删改查
    [HttpGet("All")]
    public async Task<ApiResponse<IEnumerable<CargoDto>>> GetAll() => await _service.GetAllAsync();

    [HttpGet("{id}")]
    public async Task<ApiResponse<CargoDto>> GetSingle([RequiredGuid] Guid id) => await _service.GetSingleAsync(id);

    [HttpPost("Add")]
    public async Task<ApiResponse<CargoDto>> Add(CargoDto dto) => await _service.AddAsync(dto);

    [HttpPut("{id}")]
    public async Task<ApiResponse<CargoDto>> Update([RequiredGuid] Guid id, CargoDto dto) => await _service.UpdateAsync(id, dto);

    [HttpDelete("{id}")]
    public async Task<ApiResponse<CargoDto>> Delete([RequiredGuid] Guid id) => await _service.DeleteAsync(id);

    #endregion

    #region 扩展查询
    [HttpGet("MtlNumber")]
    public async Task<ApiResponse<CargoDto>> GetSingleByMtlNumber(string mtlNumber) => await _service.GetSingleByMtlNumberAsync(mtlNumber);
    //http://10.9.18.31/api/Cargo/MtlNumber?mtlNumber=xxxx

    [HttpGet("Area")]
    public async Task<ApiResponse<IEnumerable<CargoDto>>> GetAllByArea(Warehouse_e warehouse, Area_e area,string ranks) => await _service.GetAllByAreaAsync(warehouse, area,ranks);
    //http://10.9.18.31/api/Cargo/Area?warehouse=xxxx&area=xxxx&ranks=xxx

    [HttpGet("Location")]
    public async Task<ApiResponse<CargoDto>> GetSingleByLocation(string location) => await _service.GetSingleByLocationAsync(location);
    //http://10.9.18.31/api/Cargo/Location?location=xxxx

    #endregion

    #region 需要带上库存的查询 
    [HttpGet("Inventory/Top5")]
    public async Task<ApiResponse<IEnumerable<CargoDto>>> GetGetTop5ByKeywordWithInventory(string? keyword) => await _service.GetTop5ByKeywordWithInventoryAsync(keyword);
    //http://10.9.18.31/api/Cargo/Inventory/Top5?keyword=xxxx
    [HttpGet("Inventory/{id}")]
    public async Task<ApiResponse<CargoDto>> GetSingleWithInventory([RequiredGuid] Guid id) => await _service.GetSingleWithInventoryAsync(id);

    [HttpGet("Inventory/All")]
    public async Task<ApiResponse<IEnumerable<CargoDto>>> GetAllWithInventory() => await _service.GetAllWithInventoryAsync();

    [HttpGet("Inventory/Area")]
    public async Task<ApiResponse<IEnumerable<CargoDto>>> GetAllByAreaWithInventory(Warehouse_e warehouse, Area_e area, string ranks) => await _service.GetAllByAreaWithInventoryAsync(warehouse, area, ranks);
    //http://10.9.18.31/api/Cargo/Inventory/Area?warehouse=xxxx&area=xxxx&ranks=xxx


    #endregion


    #region MAUI

    [HttpGet("Maui/All")]
    public async Task<ApiResponse<IEnumerable<CargoDto>>> GetMauiAllWithInventory(int skip, int take, string? search = null) => await _service.GetMauiAllWithInventoryAsync(skip,take,search);

    [HttpGet("Maui/Area")]
    public async Task<ApiResponse<IEnumerable<CargoDto>>> GetMauiAllByAreaWithInventory(Warehouse_e warehouse, Area_e area, string ranks, string? search = null) => await _service.GetMauiAllByAreaWithInventoryAsync(warehouse, area, ranks,search);
    #endregion
}